
/**
 * Copyright 2009 cestum.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package org.waveprotocol.wave.model.document.operation.impl {
import org.goverla.collections.ArrayList;
import org.goverla.collections.HashMap;
import org.waveprotocol.wave.model.document.operation.Attributes;
import org.waveprotocol.wave.model.document.operation.AttributesUpdate;
import org.waveprotocol.wave.model.document.operation.util.ImmutableAttributesStateMap;
import org.waveprotocol.wave.model.document.operation.util.StateMap;

public class AttributesImpl extends ImmutableAttributesStateMap implements Attributes {
	
	public static function of(map:HashMap):AttributesImpl {
		return new AttributesImpl(ImmutableAttributesStateMap.attributeListFromMap(map));
	}
	
	public function AttributesImpl(attributes:ArrayList) {
		super(attributes);
	}
	
	override protected function createFromList(attributes:ArrayList):Attributes {
		return new AttributesImpl(attributes);
	}
	
	public static function fromSortedAttributes(sortedAttributes:ArrayList):StateMap {
		checkAttributesSorted(sortedAttributes);
		return fromSortedAttributesUnchecked(sortedAttributes);
	}
	
	public static function fromSortedAttributesUnchecked(
		sortedAttributes:ArrayList):AttributesImpl {
		return new AttributesImpl(sortedAttributes);
	}
//	public static function fromUnsortedAttributes(List<Attribute> unsortedAttributes):AttributesImpl {
//		List<Attribute> sorted = new ArrayList<Attribute>(unsortedAttributes);
//		Collections.sort(sorted, comparator);
//		// Use the checked variant here to check for duplicates.
//		return fromSortedAttributes(sorted);
//	}
	
	override public function updateWith(mutation:AttributesUpdate, checkCompatibility:Boolean=false):Attributes {
		return Attributes(super.updateWith1(mutation));
	}
	
	override public function updateWithNoCompatibilityCheck(mutation:AttributesUpdate):Attributes {
		return Attributes(super.updateWithNoCompatibilityCheck(mutation));
	}
	
	
}
}